package com.ruoyi.cderp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cderp.domain.BaseDataAddress;
import com.ruoyi.cderp.service.IBaseDataAddressService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地址库Controller
 *
 * @author ruoyi
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/system/Address")
public class BaseDataAddressController extends BaseController
{
    @Autowired
    private IBaseDataAddressService baseDataAddressService;

    /**
     * 查询地址库列表
     */
    @PreAuthorize("@ss.hasPermi('system:Address:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseDataAddress baseDataAddress)
    {
        startPage();
        List<BaseDataAddress> list = baseDataAddressService.selectBaseDataAddressList(baseDataAddress);
        return getDataTable(list);
    }

    /**
     * 导出地址库列表
     */
    @PreAuthorize("@ss.hasPermi('system:Address:export')")
    @Log(title = "地址库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseDataAddress baseDataAddress)
    {
        List<BaseDataAddress> list = baseDataAddressService.selectBaseDataAddressList(baseDataAddress);
        ExcelUtil<BaseDataAddress> util = new ExcelUtil<BaseDataAddress>(BaseDataAddress.class);
        util.exportExcel(response, list, "地址库数据");
    }

    /**
     * 获取地址库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:Address:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(baseDataAddressService.selectBaseDataAddressById(id));
    }



    /**
     * 新增地址库
     */
    @PreAuthorize("@ss.hasPermi('system:Address:add')")
    @Log(title = "地址库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseDataAddress baseDataAddress)
    {
        return toAjax(baseDataAddressService.insertBaseDataAddress(baseDataAddress));
    }

    /**
     * 修改地址库
     */
    @PreAuthorize("@ss.hasPermi('system:Address:edit')")
    @Log(title = "地址库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseDataAddress baseDataAddress)
    {
        return toAjax(baseDataAddressService.updateBaseDataAddress(baseDataAddress));
    }

    /**
     * 删除地址库
     */
    @PreAuthorize("@ss.hasPermi('system:Address:remove')")
    @Log(title = "地址库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(baseDataAddressService.deleteBaseDataAddressByIds(ids));
    }


}
